home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-07-31 | 3.6 KB | 120 lines | [TEXT/MMCC] |
- /**************************************************************************
- LGBDeviceIterator
-
- Public domain, by Zig Zichterman.
-
- a class that iterates over all devices. Does NOT do fancy-schmancy
- constructor/destructor things (so that I won't incur C++ runtime
- overhead in my CDEF)
-
- 07/31/94 zz add mDeviceIsColor
- 07/31/94 zz move color QD gestalt to UGBDraw::ColorQDIsPresent()
- **************************************************************************/
- #include "LGBDeviceIterator.h"
-
- #include "UGBDraw.h"
-
- /**************************************************************************
- Init()
-
- Initialize a device iterator. I do the initialization here instead
- of a constructor so that I don't accidentally bring in the C++
- runtime engine, which is too expensive for my puny CDEF codesize.
- **************************************************************************/
- void
- LGBDeviceIterator::Init(const Rect &inLocalRect)
- {
- mNextDevice = NULL;
- mNeedsOldQD = false;
- mDoneOldQD = false;
-
- mGlobalRect = inLocalRect;
- ::LocalToGlobal(&(topLeft(mGlobalRect)));
- ::LocalToGlobal(&(botRight(mGlobalRect)));
-
- // do we have color QD? If not, just set up
- // a couple flags and return before we
- // crash the machine with color QD calls
- if (!UGBDraw::ColorQDIsPresent()) {
- mNeedsOldQD = true;
- return;
- }
-
- { // is the current port a color grafport? if not,
- // pretend we're a 1-bit device (because we are)
- CGrafPtr port;
- ::GetPort((GrafPtr *) &port);
- if ((port->portVersion & 0xC000) != 0xC000) {
- // not a color grafport. Only do 1-bit
- mNeedsOldQD = true;
- return;
- }
- }
-
- // we have color QD. safe to walk the device list
- mNextDevice = ::GetDeviceList();
- }
-
- /**************************************************************************
- Next()
-
- Does the next device intersect our rect? If not, keep
- moving through the device list until we find one that
- does. Return the depth of the screen that does.
-
- Return 0 if we fall off the end of the list without
- finding any screens that intersect our rect
- **************************************************************************/
- short
- LGBDeviceIterator::Next(void)
- {
- short depth = 0;
-
- // if we're on a color-QD-challenged device,
- // don't make any color QD calls
- // (like walking the device list)
- if (mNeedsOldQD) {
- if (!mDoneOldQD) { // this is our first call to Next()
- depth = 1; // return a 1-bit depth
- mDoneOldQD = true; // and only do this once
- }
- return depth;
- }
- // safe to call color QD now
-
- // does the current device intersect? If not,
- // keep qlking until we find a match
- for (;mNextDevice;
- mNextDevice = ::GetNextDevice(mNextDevice)) {
- // skip over non-monitor devices
- if ((::TestDeviceAttribute(mNextDevice,screenDevice) == 0)
- || (::TestDeviceAttribute(mNextDevice,screenActive) == 0)) {
- continue; // not a screen. Keep looking
- }
-
- Rect deviceBounds = (*mNextDevice)->gdRect;
- Rect intersect;
- if (!::SectRect(&deviceBounds,&mGlobalRect,&intersect)) {
- continue; // no intersection. Keep looking
- }
-
- // clip to the intersection of the device and our rect
- // ClipRect() thinks in local coords, so convert
- ::GlobalToLocal(&topLeft(intersect));
- ::GlobalToLocal(&botRight(intersect));
- ::ClipRect(&intersect);
- depth = (*(*mNextDevice)->gdPMap)->pixelSize;
-
- // is the device color?
- mDeviceIsColor = ((**mNextDevice).gdFlags & 0x0001)?true:false;
-
- // we're going to break out of the loop without calling
- // the loop-end incrementer (the part of the for-statement
- // that moves mNextDevice to the next device). So call it
- // explicitly before the breakout
- mNextDevice = ::GetNextDevice(mNextDevice);
- break;
- }
- return depth;
- }
-